﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RytmSerca
{
    /// <summary>
    /// Interaction logic for Dots.xaml
    /// </summary>
    public partial class Dots : UserControl
    {
        public Dots()
        {
            InitializeComponent();
        }

        public static DependencyProperty DotCountProperty = DependencyProperty.Register("DotCount", typeof (int), typeof (Dots),
                                                                                 new PropertyMetadata(3, OnDotCountChanged));

        public static DependencyProperty AnimateProperty = DependencyProperty.Register("Animate", typeof (bool), typeof (Dots),
                                                                                 new PropertyMetadata(true));

        public bool Animate
        {
            get { return (bool) GetValue(AnimateProperty); }
            set { SetValue(AnimateProperty, value); }
        }
        private static void OnDotCountChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var dotContainer = (StackPanel) ((Dots) d).FindName("dotsContainer");
            var newValue = (int) e.NewValue;
            dotContainer.Children.Clear();
            for (int i = 0; i < newValue; i++)
            {
                dotContainer.Children.Add(new TextBlock
                                              {
                                                  Text = ".",
                                                  Margin = new Thickness(1, 0, 1, 0)
                                              });
            }
        }

        public int DotCount
        {
            get { return (int) GetValue(DotCountProperty); }
            set { SetValue(DotCountProperty, value); }
        }
    }
}
